package com.bytecodezz.app.photoshop.loader.base

import android.app.Activity
import android.content.Context
import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import android.net.Uri
import android.widget.ImageView
import androidx.fragment.app.Fragment
import com.bytecodezz.app.photoshop.loader.listener.BitmapLoaderListener
import com.bytecodezz.app.photoshop.loader.listener.DrawableLoaderListener
import com.bytecodezz.app.photoshop.loader.listener.FileLoaderListener
import java.io.File
import java.lang.Exception

/**
 * 承载图片加载的具体参数配置
 * 设计模式：builder设计模式、享元设计模式
 * 通过builder进行图片加载对象构建
 * 通过共享对象池对创建的对象进行复用（借鉴Android Handler msg创建方式）
 */
abstract class IPhotoshopLoaderBuilder {
    /**
     * 回收builder对象
     */
    open fun recycleUnchecked() {
        context = null
        fragment = null
        activity = null

        url = null
        file = null
        resourceId = null
        uri = null
        bitmap = null
        drawable = null
        byteArray = null

        isBitmap = false
        isDrawable = false
        isFile = false
        isGif = false
        bitmapListener = null
        fileListener = null
        drawableListener = null

        errorResourceId = null
        errorDrawable = null
        errorBitmap = null

        preWidth = null
        preHeight = null
    }

    var context: Context? = null
    var fragment: Fragment? = null
    var activity: Activity? = null

    var url: String? = null
    var file: File? = null
    var resourceId: Int? = null
    var uri: Uri? = null
    var bitmap: Bitmap? = null
    var drawable: Drawable? = null
    var byteArray: ByteArray? = null

    var isOnlyDownload: Boolean = false
    var isBitmap: Boolean = false
    var isDrawable: Boolean = false
    var isFile: Boolean = false
    var isGif: Boolean = false

    var bitmapListener: BitmapLoaderListener? = null
    var fileListener: FileLoaderListener? = null
    var drawableListener: DrawableLoaderListener? = null

    var errorResourceId: Int? = null
    var errorDrawable: Drawable? = null
    var errorBitmap: Bitmap? = null

    var preWidth: Int? = null
    var preHeight: Int? = null

    var imageView: ImageView? = null


}